package com.jinke.uang.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.jinke.uang.R;

import androidx.annotation.NonNull;


public class SelectImgDialog extends Dialog implements View.OnClickListener {

    private View rootView;
    private TextView tv_take_photo;
    private TextView tv_take_picture;
    private TextView tv_cancel;
    private SelectImgDialogClickListener mClickListener;

    public SelectImgDialog(@NonNull Context context) {
        super(context);
        init();
    }

    public SelectImgDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    protected SelectImgDialog(@NonNull Context context, boolean cancelable,OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init();
    }

    private void init() {
        rootView = LayoutInflater.from(getContext()).inflate(R.layout.layout_of_select_img_dialog, null);
        tv_take_photo = rootView.findViewById(R.id.tv_take_photo);
        tv_take_picture = rootView.findViewById(R.id.tv_take_picture);
        tv_cancel = rootView.findViewById(R.id.tv_cancel);

//        WindowManager.LayoutParams attributes = getWindow().getAttributes();
//        attributes.gravity= Gravity.BOTTOM;
        setCanceledOnTouchOutside(false);
        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().setWindowAnimations(R.style.select_dialog_animation);
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        setContentView(rootView);

        initListener();

    }

    public void setSelectListener(SelectImgDialogClickListener listener) {
        this.mClickListener = listener;
    }

    private void initListener() {
        tv_cancel.setOnClickListener(this);
        tv_take_photo.setOnClickListener(this);
        tv_take_picture.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_take_picture:

                dismiss();
                if (mClickListener != null) {
                    mClickListener.onSelectPictureClick();

                }
                break;
            case R.id.tv_take_photo:
                dismiss();
                if (mClickListener != null) {
                    mClickListener.onTakePhotoClick();

                }
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
        }

    }

    public static interface SelectImgDialogClickListener {
        void onTakePhotoClick();

        void onSelectPictureClick();

    }
}
